﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {

            }
            else
            {
                Response.Write("<script>alter('欢迎来到登录界面')</script>");
            }
        }
        #region 登录按钮
        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = this.TextBox1.Text;
            string password = this.TextBox2.Text;

            if (username.Equals("") || password.Equals(""))
            {
                Response.Write("账号或密码不能为空！");
            }
            else
            {
                string sql = string.Format("select * from Users where username='{0}'and password='{1}'", username, password);
                
                var count = DbHelper.GetDatatable(sql);

                if (count.Rows.Count > 0)
                {
                    var value = count.Rows[0];
                    
                    var IsActived = (bool)value.ItemArray[3];

                    var IsDeleted = (bool)value.ItemArray[4];

                    if (IsDeleted)
                    {
                        Response.Write("账号已被删除！");
                    }
                    else
                    {
                        if (IsActived)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Response.Write("账号已被停用！");
                        }
                    }
                }
                else
                {
                    Response.Write("账号或密码错误！");
                }

            }
        }
        #endregion
    }
}